package com.jrx.anytxn.transaction.mapper.ext;

import com.jrx.anytxn.transaction.entity.AmRepaymentPlanInfo;
import com.jrx.anytxn.transaction.entity.AmWaiveRepaymentPlanInfo;
import org.apache.ibatis.annotations.Param;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 还款计划扩展
 *
 * @author haopu.zheng
 * date  2019/7/25
 **/
public interface ExtAmWaiveRepaymentPlanInfoMapper {

    /**
     * 通过贷款ID及状态(数组传值)获取贷款计划
     *
     * @param loanId     订单id
     * @param status     状态数组
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return java.util.List<com.jrx.anytxn.transaction.entity.AmRepaymentPlanInfo>
     * @author : zhenghaopu
     * date: 2019/9/25
     */
    List<AmWaiveRepaymentPlanInfo> selectRepaymentPlanInfoListByLoanIdAndStatus(@Param(value = "loanId") String loanId,
                                                                                @Param(value = "statusArrays") String[] status,
                                                                                @Param(value = "customerId") String customerId,
                                                                                @Param("tenantId") String tenantId);

    /**
     * 批量插入还款计划
     *
     * @param amWaiveRepaymentPlanInfoList 还款计划列表
     * @return void
     * @author : zhenghaopu
     * date: 2019/9/25
     */
    void insertAmWaiveRepaymentPlanInfoList(List<AmWaiveRepaymentPlanInfo> amWaiveRepaymentPlanInfoList);

    /**
     * 根据条件查询还款计划数据
     *
     * @param cond 条件
     * @return 还款计划数据
     */
    List<AmWaiveRepaymentPlanInfo> selectByCondSelective(AmWaiveRepaymentPlanInfo cond);

    List<AmWaiveRepaymentPlanInfo> selectPlanListByCondSelective(@Param("customerId") String customerId, @Param("tenantId") String tenantId, @Param("loanId") String loanId);

    /**
     * 根据条件查询还款计划
     *
     * @param loanId
     * @param status
     * @param customerId
     * @param tenantId
     * @return
     */
    List<AmWaiveRepaymentPlanInfo> selectByLoanIdAndStatus(@Param(value = "loanId") String loanId,
                                                      @Param(value = "statusList") List<String> status,
                                                      @Param(value = "customerId") String customerId,
                                                      @Param(value = "tenantId") String tenantId);

    /**
     * 批量更新还款计划（用于联机）
     *
     * @param amRepaymentPlanInfos
     * @return
     */
    int batchUpdatePlan(List<AmWaiveRepaymentPlanInfo> amRepaymentPlanInfos);

    /**
     * 批量更新还款计划（用于批量）
     *
     * @param amRepaymentPlanInfos
     * @return
     */
    int batchUpdatePlanForBatch(List<AmWaiveRepaymentPlanInfo> amRepaymentPlanInfos);

    /**
     * 根据主键及客户id及租户id修改还款计划
     *
     * @param amRepaymentPlanInfo
     * @return
     */
    int updateByIdAndCustomerIdAndTenantId(AmWaiveRepaymentPlanInfo amRepaymentPlanInfo);

    /**
     * 根据订单号、期数、状态、客户id、租户id查询还款计划
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param billingTenor
     * @param status
     * @return
     */
    AmWaiveRepaymentPlanInfo selectByLoanIdAndBillingTenor(@Param(value = "loanId") String loanId,
                                                      @Param(value = "customerId") String customerId,
                                                      @Param(value = "tenantId") String tenantId,
                                                      @Param(value = "billingTenor") Integer billingTenor,
                                                      @Param(value = "statusList") List<String> status);

    /**
     * 根据还款计划状态获取还款计划
     *
     * @param planStatus
     * @return
     */
    List<AmWaiveRepaymentPlanInfo> selectByStatusAndPaymentDate(@Param(value = "planStatus") String planStatus,
                                                           @Param(value = "today") Date today,
                                                           @Param(value = "lastProcessingDay") Date lastProcessingDay);

    /**
     *根据更新时间查询还款计划表
     * @param startTime
     * @param endTime
     * @return
     */

    List<AmWaiveRepaymentPlanInfo> selectRepaymentPlanInfoListByUpdateTimeSelective(@Param(value = "startTime") String startTime,
                                                                               @Param(value = "endTime") String endTime);

    /**
     * 根据loanid和更新时间查询还款计划
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param startTime
     * @param endTime
     * @return
     */
    List<AmWaiveRepaymentPlanInfo> selectRepaymentPlanInfoListByUpdateTimeAndLoanIdSelective(@Param(value = "loanId") String loanId, @Param(value = "customerId") String customerId, @Param(value = "tenantId") String tenantId, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime);

    /**
     * 根据产品ID和还款日期查询还款计划
     * @param productId
     * @param paymentDueDate
     * @return
     */
    List<AmWaiveRepaymentPlanInfo> selectByProductIdAndPaymentDueDate(@Param(value = "productId") String productId, @Param(value = "paymentDueDate") Date paymentDueDate);

    AmWaiveRepaymentPlanInfo selectByLoanIdAndTenor(@Param("customerId") String customerId, @Param("tenantId") String tenantId,
                                               @Param("channel") String channel, @Param("loanId") String loanId,
                                               @Param("billingTenor") String billingTenor);

    /**
     * 查询当前逾期还款计划
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    AmWaiveRepaymentPlanInfo selectMaxOverPlan(@Param(value = "loanId") String loanId, @Param(value = "customerId") String customerId, @Param(value = "tenantId") String tenantId);


    /**
     * 根据条件查询还款计划 （排除取消的）
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    List<AmWaiveRepaymentPlanInfo> selectByLoanId(@Param(value = "loanId") String loanId,
                                             @Param(value = "customerId") String customerId,
                                             @Param(value = "tenantId") String tenantId);

    /**
     * 根据条件查询还款计划升序 （排除取消和未抛账的）
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    List<AmWaiveRepaymentPlanInfo> selectByLoanIdAsc(@Param(value = "loanId") String loanId,
                                                @Param(value = "customerId") String customerId,
                                                @Param(value = "tenantId") String tenantId);

    /**
     * 累计代偿次数统计
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    int selectCountByCmps(@Param(value = "loanId") String loanId,
                          @Param(value = "customerId") String customerId,
                          @Param(value = "tenantId") String tenantId);

    /**
     * 查询待扣款还款计划
     * @param paymentDueDate
     * @return
     */
    List<AmWaiveRepaymentPlanInfo> selectAllForBatch(@Param(value = "paymentDueDate") Date paymentDueDate);
}
